<?php
namespace app\common\controller;
use think\Controller;
use think\Db;
use think\Request;
class Base extends Controller{
    protected $post;
    protected $p;
    public function _initialize(){
        $this->post = $this->request->post();
        $p = input('p',0,'intval');
        $this->p = $p <= 0?1:$p;
        
    }

    /**
     * 接口返回封装
     */
    protected function apiReturn($status='-1',$msg,$data=[]){
        if(empty($data)){
            $data = [];
        }
        exit(json_encode(array('code'=>$status,'msg'=>$msg,'data'=>$data)));
    }
    
    /**
     * [user_check 会员校验]
     * @return [type] [description]
     */
    protected function user_check($token=''){
        if($token == ''){
            $this->apiReturn(-1,'非法访问');
        }

        $Aes = new \Aes\Aes();
        $token = $Aes->aes128cbcHexDecrypt($token);
        $user = model('common/user')->getUserInfo(['token'=>$token],'*');

        if(is_null($user)){
            $this->apiReturn(-1,'无权访问');
        }

        if($user['disabled'] == 0){
            $this->apiReturn(-1,'该会员被禁用');
        }
        /*if($user['photo_path'] == '' || $user['nick_name'] == '' || $user['zhiye'] == 0 || $user['tel'] == '' ){
            $this->apiReturn(0,'请先完善个人基本信息');
        }

        if($user['from_lng'] == '' || $user['from_lat'] == '' || $user['from_city'] == ''){
            $this->apiReturn(0,'请添加地点管理');
        }*/
        define('UID',$user['id']);
        
    }
}
